<script setup lang="ts">
import { RouterLink, RouterView } from 'vue-router'
import HelloWorld from '../components/HelloWorld.vue'
import { Menu as IconMenu, Setting as IconSetting } from '@element-plus/icons-vue';
import { useCounterStore } from "@/stores/counter"
import { useRouter } from 'vue-router';
const store = useCounterStore()
const router = useRouter()
const logintoor = () => {
  router.push({
    name: 'Loing'
  })
}
</script>

<template>
  <div class="common-layout">
    <el-container>
      <!-- 头部 -->
      <el-header>
        <el-row align="middle" justify="space-between">
          <el-col :span="12">
            <span class="logo">爱吃兔溯源</span>
          </el-col>
          <el-col :span="12" style="text-align: right;">
            <el-button type="text" style="color: #333;font-size:17px;margin-right:30px;">{{
              store.accountcounter.roleName }}&nbsp&nbsp&nbsp;欢迎回来，{{
                store.accountcounter.accountNickName
              }}</el-button>
            <el-button type="danger" style="margin-right:15px;" @click="logintoor">退出登录</el-button>
          </el-col>
        </el-row>
      </el-header>

      <!-- 主体 -->
      <el-container>
        <!-- 侧边栏 -->
        <el-aside width="200px">
          <el-menu style="height: calc(100vh - 60px);" active-text-color="#409EFF" background-color="#ffffff"
            text-color="#333333" default-active="/Source" router>
            <el-menu-item index="/Source">
              <el-icon><icon-menu /></el-icon>
              <span>溯源管理</span>
            </el-menu-item>
            <!-- 可以继续添加其他菜单项 -->
            <el-menu-item index="/Other">
              <el-icon><icon-setting /></el-icon>
              <span>其他功能</span>
            </el-menu-item>
          </el-menu>
        </el-aside>

        <!-- 主内容区 -->
        <el-main>
          <RouterView />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<style scoped>
.common-layout {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* 防止页面滚动 */
}

.el-header {
  height: 60px;
  line-height: 60px;
  background-color: #ffffff;
  color: #333;
  padding: 0 20px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.logo {
  font-size: 20px;
  font-weight: bold;
  color: #409EFF;
  /* 品牌色 */
}

.el-aside {
  background-color: #ffffff;
  border-right: 1px solid #e4e7ed;
  /* 添加边框分隔 */
}

.el-menu {
  border-right: none;
}

.el-menu-item {
  transition: background-color 0.3s;
}

.el-menu-item:hover {
  background-color: #f5f7fa !important;
  /* 鼠标悬停背景色 */
}

.el-main {
  padding: 20px;
  background-color: #f5f7fa;
  /* 主内容区背景色 */
  overflow-y: auto;
  /* 允许主内容区内部滚动 */
  height: calc(100vh - 60px);
  /* 确保主内容区高度适应 */
}
</style>